using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Practices.RecipeFramework;
using System.Xml;
using Microsoft.Practices.RepositoryFactory.CommonHelpers;
using EnvDTE;

namespace Microsoft.Practices.RepositoryFactory.Actions
{
    public class PersistRecipeStateAction : Microsoft.Practices.RecipeFramework.Action
    {
        private string solutionPath;

        [Input(Required = true)]
        public string SolutionPath
        {
            get { return solutionPath; }
            set { solutionPath = value; }
        }

        private string solutionName;

        [Input(Required = true)]
        public string SolutionName
        {
            get { return solutionName; }
            set { solutionName = value; }
        }

        private XmlDocument recipeState;

        [Input(Required=true)]
        public XmlDocument RecipeState
        {
            get { return recipeState; }
            set { recipeState = value; }
        }


        public override void Execute()
        {


            string fileName = string.Format(@"{0}\{1}.rcpstate", solutionPath, solutionName);
            DTE vs = GetService<DTE>(true); 
            TFSHelper.CheckOutFile(vs, fileName);
            recipeState.Save(fileName);
        }

        public override void Undo()
        {
            
        }
    }
}
